import time

from selenium.webdriver.common.by import By

from base.app_base_page import AppBasePage


class PageSearch(AppBasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.__home_img = (By.ID, "com.tpshop.malls:id/home_img")
        self.__search_et = (By.ID, "com.tpshop.malls:id/default_search_et")
        self.__input_search = (By.ID, "com.tpshop.malls:id/search_et")
        self.__search_btn = (By.ID, "com.tpshop.malls:id/search_btn")
        self.__search_success = (By.ID, "com.tpshop.malls:id/product_name_tv")

    def page_search(self, text):
        self.app_base_click(self.__home_img)
        self.app_base_click(self.__search_et)
        self.app_base_send_keys(self.__input_search, text)
        self.app_base_click(self.__search_btn)

    def get_search_success(self):
        time.sleep(1)
        return self.app_fd_element(self.__search_success).text
